package com.huawei.springboot2023.business.customattr.controller;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huawei.springboot2023.business.customattr.dto.Customattr;
import com.huawei.springboot2023.business.customattr.service.ICustomattrService;
import com.huawei.springboot2023.business.user.dto.User;
import com.huawei.springboot2023.core.dto.MyResult;
import com.huawei.springboot2023.core.util.MyUUID;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhouChengYang
 * @since 2023-04-07
 */
@RestController
@RequestMapping("/customattr")
public class CustomattrController {

    @Resource(name = "customattrServiceImpl")
    private ICustomattrService customAttrService;

    @PostMapping("/add")
    @ApiOperation("自定义属性添加")
    public MyResult add(String customAttrMsg){

        MyResult result = new MyResult();
        System.out.println(customAttrMsg);

        String uuid = MyUUID.getUUID();

        Customattr customattr = new Customattr();
        customattr.setCustomAttrId(uuid);
        customattr.setCustomAttrMsg(customAttrMsg);


        try {
            boolean save = customAttrService.save(customattr);
            if(save){
                result.setMsg("添加成功！");
            }else{
                result.setMsg("添加失败！");
                result.setCode("9999");
            }
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("新增异常！");
            result.setCode("9999");
        }



        return result;

    }



}
